<?php
include_once("../includes/page_utf_class.php");
include_once("../module/payment/lang/$config[language].php");
include_once("../module/payment/includes/charge_type.php");
include_once("../module/product/includes/plugin_tarento_class.php");

$tarento = new Tarento();
//=============================================

//给会员充值
if(!empty($_POST["charge"])&&!empty($_POST["cash"])&&is_numeric($_POST["cash"]))
{
	$_POST['cash']=$_POST['cash']*1;
	
	$sql="select account from ".TARENTO." where member_id='$_GET[member_id]' and status>0";
	$db->query($sql);
	$v=$db->fetchRow();
	
	unset($_GET['m']);
	unset($_GET['s']);
	unset($_GET['act']);
	//-----------是否开通支付账号
	if(!empty($v))
	{
		$tarento->change_member_account($_GET['member_id'],$_POST['cash'],$_POST['type_code'],$_POST['description']);
		
		admin_msg('module.php?m=payment&s=payment_user.php&'.implode('&',convert($_GET)),'操作成功');
	}
	else
	{
		admin_msg('module.php?m=payment&s=payment_user.php&'.implode('&',convert($_GET)),'会员账户已冻结,请先开通账户');
	}
}

//=============================
if(!empty($_GET['stime']))
{
	$stime=($_GET['stime']);
	$sql.=" and a.create_time>='$stime 00:00:00' ";
}
if(!empty($_GET['etime']))
{
	$etime=($_GET['etime']);
	$sql.=" and a.create_time<='$etime 23:59:59'";
}
if ($_GET['member_id']&&preg_match("/^[\d,]+$/", $_GET['member_id'])){
	 $sql.= " and a.member_id in({$_GET['member_id']})";
}
	
$sqlg="select a.*,b.mobile,b.name from ".CASHFLOW." as a left join ".MEMBER." as b on a.member_id=b.userid where 1  $sql order by create_time desc";
//-----------------------------------
$page = new Page;
$page->listRows=20;
if (!$page->__get('totalRows'))
{
	$db->query($sqlg);
	$page->totalRows = $db->num_rows();
}
$sqlg .= "  limit ".$page->firstRow.",20";
$pages = $page->prompt();
$db->query($sqlg);
$rg=$db->getRows();

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="main.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="main.js"></script>
<script language="javascript" src="../script/Calendar.js"></script>
<title><?php echo lang_show('admin_system');?></title>
</head>
<body>
<script>
function check_value()
{
	var v=document.getElementById("cash").value*1;
	if(!v){
		alert('请确认金额！');
		return false;
	}
	return confirm('<?php echo lang_show('surec');?>')
}
</script>
<div class="bigbox" <?php if($_GET['act']=='add') echo 'style="display:block;"';else echo 'style="display:none;"';?>>
  <div class="bigboxhead tab" style=" width:90%">
	  <span class="cbox"><a href="module.php?m=payment&s=member_charge.php"><?php echo lang_show('clist');?></a></span>
	  <span class="cbox on"><a href=""><?php echo lang_show('mc');?></a></span>
  </div>
  <div class="bigboxbody" style="margin-top:-1px;">
    <form name="frmuser" method="POST" action="" onsubmit="return check_value();">
      <table width="100%" border="0" cellspacing="0" cellpadding="0">
      <?php if($_GET['member_id']){?>
        <tr>
          <td  class="searh_left">充值会员</td>
          <td><?php echo $_GET['member_id']; ?></td>
        </tr>
        <tr>
        	<td>充值类型</td>
        	<td>
        		<select name="type_code">
        			<?php foreach ($charge_type as $ctk=>$ctv){?>
        			<option value="<?php echo $ctk;?>"><?php echo $ctv['type_name']?></option>
        			<?php }?>
        		</select>
        	</td>
        </tr>
        <tr>
        	<td>充值备注</td>
        	<td>
        		<textarea style="resize:both;width:200px;height:100px;" name="description"></textarea>
        	</td>
        </tr>
        <tr>
          <td><?php echo lang_show('cmount');?></td>
          <td><input class="text" name="cash" type="text" id="cash" size="10" maxlength="10" onkeyup="" />
            <span class="bz">正值为加,负值为扣</span></td>
        </tr>
        <tr>
          <td>&nbsp;</td>
          <td><input class="btn" type="submit" name="charge" id="charge" value="<?php echo lang_show('sc');?>" /></td>
        </tr>
        <?php }else{?>
        <tr>
          <td colspan="2"><font color="red"><?php echo lang_show('nou');?></font></td>
        </tr>
        <?php }?>
      </table>
    </form>
  </div>
</div>
<div class="bigbox" <?php if($_GET['act']=='') echo 'style="display:block;"';else echo 'style="display:none;"';?>>
  <div class="bigboxhead tab" style="width:90%">
  <span class="cbox on"><a href=""><?php echo lang_show('clist');?></a></span>
  </div>
  <div class="bigboxbody" style="margin-top:-1px;">
    <table width="100%" border="0" cellspacing="0" cellpadding="0" align="center" class="menu">
      <tr height="25">
        <td height="107" colspan="7"  align="left"><form action="" method="get">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr>
                <td style="border:none" class="searh_left">会员</td>
                <td style="border:none">
                <textarea rows="" cols="" name="member_id"><?php echo  $_GET['member_id'];?></textarea>
                  <span class="bz">会员ID，支持逗号分隔的多个</span></td>
                <td style="border:none">
                                    时间
                <script language="javascript">
                    var cdr = new Calendar("cdr");
                    document.write(cdr);
                    cdr.showMoreDay = true;
                    </script>
                </td>
                <td style="border:none"><input onFocus="cdr.show(this);" class="ltext" value="<?php echo $_GET['stime'];?>" name="stime" type="text" id="stime">
                  --
                  <input onFocus="cdr.show(this);" class="rtext" value="<?php echo $_GET['etime'];?>" name="etime" type="text" id="etime">
                </td>
              </tr>
              <tr>
                <td colspan="99"><input name="Submit" type="submit" class="btn" value="搜索"></td>
              </tr>
            </table>
            <input name="m" type="hidden" value="payment" />
            <input name="s" type="hidden" value="member_charge.php" />
          </form></td>
      </tr>
      <tr class="theader">
        <td width="154" align="left">序号</td>
        <td width="148" align="left">会员ID</td>
        <td width="148" align="left">会员</td>
        <td width="100" align="left">金额</td>
        <td align="left">备注</td>
        
        <td width="50" align="left">操作</td>
        <td width="172" align="left">时间</td>
      </tr>
    <?php
    if ($rg){
	foreach($rg as $k=> $v)
	{
	 ?>
      <tr>
        <td align="left"><?php echo $k+1;?></td>
        <td> <?php echo $v['member_id'];?></td>
        <td align="left"><?php echo $v['name'].'('.$v['mobile'].')';?></td>
        <td align="10%"><?php echo $config['money'].$v['price'];?></td>
        <td align="10%"><?php echo $v['description'];?></td>
         <td align="10%"><?php echo $v['extension'];?></td>
        <td align="left"><?php echo $v['create_time'];?></td>
   </tr>
      <?php
		}
    }else{
        ?>
        <td colspan="7" align="center" >暂无记录</td>
        <?php 
    }
		?>
      <tr>
        <td colspan="7" align="right" ><div class="page"><?php echo $pages?></div></td>
      </tr>
    </table>
  </div>
</div>
</body>
</html>
